<?php

namespace App\B2BProject\Custom\Business;

use App\B2BProject\Custom\Member;
use Illuminate\Database\Eloquent\Model;

class OrderOperatorHistory extends Model
{
    /**
     * 获取对应订单
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function order()
    {
        return $this->belongsTo('App\B2BProject\Custom\Business\Order', 'order_id', 'id');
    }

    /**
     * 创建一次操作记录
     *
     * @param string    $event  事件
     * @param Member    $member 事件产生用户
     * @param string    $data   事件详情
     * @param string    $reason 事由
     * @param bool|true $status 结果
     *
     * @return static
     */
    public static function operating($event, Member $member, $data = '', $reason = '', $status = true)
    {
        $operate = new static;

        $operate->event       = $event;
        $operate->operator_id = $member->id;
        $operate->data        = $data;
        $operate->status      = $status;
        $operate->reason      = $reason;

        $operate->save();

        return $operate;
    }

    /**
     * 获取操作者
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function operator()
    {
        return $this->belongsTo('App\B2BProject\Custom\Member', 'operator_id', 'id');
    }
}
